﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Wsitech.BLL;
using System.Xml;
using Wsitech.Model;

public partial class News_Index : System.Web.UI.Page
{
    public readonly string configPath = "/Config/NewsIndex.config";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            bindRecommend();

            bindIndex();
        }
    }

    //从config文件中读取数据
    private void bindIndex()
    {
        XmlDocument mydoc = new XmlDocument();
        mydoc.Load(Server.MapPath(configPath));

        XmlNode root = mydoc.SelectSingleNode("config");

        XmlNode image = root.SelectSingleNode("image");
        if (image != null)
        {
            imgNews.ImageUrl = image.InnerText;
        }

        XmlNode news = root.SelectSingleNode("news");
        XmlNode desc = root.SelectSingleNode("description");
        if (news != null && desc != null)
        {
            string tid = news.InnerText;
            hlMore.NavigateUrl = string.Format("/News/NewsDetail.aspx?tid={0}", tid);
            TextInfo info = TextInfoBLL.Instance.GetDetail(tid);
            if (info != null)
            {
                lbTitle.Text = info.Title;
                lbContent.Text = desc.InnerText;
            }
        }

    }

    //绑定显示到首页的各类新闻
    private void bindRecommend()
    {
        //媒体报道
        int count = 0;
        repReport.DataSource = TextInfoBLL.Instance.GetActivePagedReportBySiteMapID(TextInfoBLL.SITEMAPID_REPORT, 0, 1, 3, ref count);
        repReport.DataBind();

        //公司动态
        repEvents.DataSource = TextInfoBLL.Instance.GetActivePagedListBySiteMapID(TextInfoBLL.SITEMAPID_EVENTS, 1, 3, ref count);
        repEvents.DataBind();

        //新闻稿
        repNews.DataSource = TextInfoBLL.Instance.GetActivePagedListBySiteMapID(TextInfoBLL.SITEMAPID_NEWS, 1, 3, ref count);
        repNews.DataBind();

        //视频
        repVideo.DataSource = TextInfoBLL.Instance.GetActivePagedListByParentSiteMapID(TextInfoBLL.SITEMAPID_VIDEO, 1, 3, ref count);
        repVideo.DataBind();
    }
}